package com.aabte.auth.group.domain.model;

import com.aabte.commons.ddd.shared.ValueObject;
import lombok.Getter;
import lombok.ToString;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.util.regex.Pattern;

@SuppressWarnings("all")
@Embeddable
@Getter
@ToString
public class GroupId implements ValueObject<GroupId> {

    private static final Pattern PATTERN_ID = Pattern.compile("^[a-z0-9]{32}$");

    @Column(name = "group_id", length = 32, unique = true, nullable = false, updatable = false)
    private String id;

    private GroupId() {
    }

    public GroupId(String id) {
        this.setId(id);
    }

    private void setId(String id) {
        if (!PATTERN_ID.matcher(id).matches()) {
            throw new IllegalArgumentException("account id format incorrect. id: " + id
                    + ", usage: " + PATTERN_ID.pattern());
        }
        this.id = id;
    }

    @Override
    public boolean sameValueAs(GroupId accountId) {
        return this.id.equals(accountId.id);
    }
}
